/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package montecarlo.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

/**
 *
 * @author alucard
 */
public class mainFrame extends JFrame
{

    private JRadioButton jrCallPutFlagC;
    private JRadioButton jrCallPutFlagP;
    private ButtonGroup grCallPutFlag;
    private JTextField textS;
    private JTextField textX;
    private JTextField textT;
    private JTextField textr;
    private JTextField textb;
    private JTextField textnSteps;
    private JTextField textnSimulations;
    private JTextArea taResults;
    private JComboBox preset;
    private JPanel jpInputs;
    private JPanel jpArea;
    private JPanel jpControls;
    private JPanel jpGlobal;
    private JPanel jpGlobalTop;
    private JPanel jpGlobalMid;
    private JPanel jpGlobalBot;
    private JButton jbQuit;
    private JButton jbStart;
    private JButton jbStop;
    private JButton jbReset;
    private JLabel jlPreset;
    private JLabel jlS;
    private JLabel jlX;
    private JLabel jlT;
    private JLabel jlr;
    private JLabel jlb;
    private JLabel jlnSteps;
    private JLabel jlnSimulations;
    private JProgressBar progressBar;

    //"c", 40, 50, 0.5, 0.06, 0.10, 0.45, 168, 10000
    //String CallPutFlag, double S, double X, double T, double r, double b, double v, int nSteps, int nSimulations
    public mainFrame()
    {
        String[] test =
        {
            "test1",
            "testtesteste",
            "testing",
        };
        this.setTitle("Simple example");
        this.setSize(800, 300);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        this.jrCallPutFlagC = new JRadioButton("Call");
        this.jrCallPutFlagC.setSelected(true);
        this.jrCallPutFlagP = new JRadioButton("Put");
        this.grCallPutFlag = new ButtonGroup();
        this.grCallPutFlag.add(jrCallPutFlagC);
        this.grCallPutFlag.add(jrCallPutFlagP);
        //Yes it would have been smart to extand JTextField and redefined the constructor ...
        this.textS = new JTextField();
        this.textS.setPreferredSize(new Dimension(60, 20));
        this.textX = new JTextField();
        this.textX.setPreferredSize(new Dimension(60, 20));
        this.textT = new JTextField();
        this.textT.setPreferredSize(new Dimension(60, 20));
        this.textr = new JTextField();
        this.textr.setPreferredSize(new Dimension(60, 20));
        this.textb = new JTextField();
        this.textb.setPreferredSize(new Dimension(60, 20));
        this.textnSteps = new JTextField();
        this.textnSteps.setPreferredSize(new Dimension(60, 20));
        this.textnSimulations = new JTextField();
        this.textnSimulations.setPreferredSize(new Dimension(60, 20));
        this.taResults = new JTextArea();
        this.taResults.setPreferredSize(new Dimension(600, 300));

        this.jlS = new JLabel("S:");
        this.jlX = new JLabel("X:");
        this.jlT = new JLabel("T:");
        this.jlr = new JLabel("r:");
        this.jlb = new JLabel("b:");
        this.jlnSteps = new JLabel("nSteps:");
        this.jlnSimulations = new JLabel("nSimulations:");


        this.jpGlobal = new JPanel();
        this.jpGlobal.setLayout(new BoxLayout(this.jpGlobal, BoxLayout.PAGE_AXIS));
        this.jpGlobalTop = new JPanel(new BorderLayout());
        this.jpGlobalMid = new JPanel(new FlowLayout());
        this.jpGlobalBot = new JPanel();
        this.jpGlobalBot.setLayout(new BoxLayout(this.jpGlobalBot, BoxLayout.LINE_AXIS));
        this.jpInputs = new JPanel(new FlowLayout());
        Border loweredbevel = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
        Border title = BorderFactory.createTitledBorder(loweredbevel, "Inputs");
        this.jpInputs.setBorder(title);
        this.jpControls = new JPanel();
        this.jpControls.setLayout(new BoxLayout(this.jpControls, BoxLayout.PAGE_AXIS));
        this.jpControls.setBorder(BorderFactory.createLineBorder(Color.black));
        this.jpArea = new JPanel();
        this.jpArea.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));

        this.preset = new JComboBox(test);
        this.preset.setPreferredSize(new Dimension(180, 20));
        this.preset.setMaximumSize(this.preset.getPreferredSize());
        this.preset.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                JComboBox cb = (JComboBox) e.getSource();
                String selected = (String) cb.getSelectedItem();
            }
        });

        this.jlPreset = new JLabel("Presets");
        this.jlPreset.setAlignmentX(this.preset.getAlignmentX());

        this.jbQuit = new JButton("Quit");
        this.jbQuit.setPreferredSize(new Dimension(180, 30));
        this.jbQuit.setAlignmentX(this.preset.getAlignmentX());
        this.jbQuit.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                System.exit(0);
            }
        });

        this.jbStart = new JButton("Start");
        this.jbStart.setPreferredSize(new Dimension(180, 30));
        this.jbStart.setAlignmentX(this.preset.getAlignmentX());

        this.jbStop = new JButton("Stop");
        this.jbStop.setPreferredSize(new Dimension(180, 30));
        this.jbStop.setAlignmentX(this.preset.getAlignmentX());

        this.jbReset = new JButton("Reset");
        this.jbReset.setPreferredSize(new Dimension(180, 30));
        this.jbReset.setAlignmentX(this.preset.getAlignmentX());


        this.progressBar = new JProgressBar(0, 100);
        this.progressBar.setPreferredSize(new Dimension(780, 25));
        this.progressBar.setMaximumSize(this.progressBar.getPreferredSize());
        this.progressBar.setValue(0);
        this.progressBar.setStringPainted(true);


        //Adding elements in jPannel and eventually on the jFrame
        this.getContentPane().add(this.jpGlobal);

        this.jpInputs.add(this.jrCallPutFlagC);
        this.jpInputs.add(this.jrCallPutFlagP);
        this.jpInputs.add(this.jlS);
        this.jpInputs.add(this.textS);
        this.jpInputs.add(this.jlX);
        this.jpInputs.add(this.textX);
        this.jpInputs.add(this.jlT);
        this.jpInputs.add(this.textT);
        this.jpInputs.add(this.jlr);
        this.jpInputs.add(this.textr);
        this.jpInputs.add(this.jlb);
        this.jpInputs.add(this.textb);
        this.jpInputs.add(this.jlnSteps);
        this.jpInputs.add(this.textnSteps);
        this.jpInputs.add(this.jlnSimulations);
        this.jpInputs.add(this.textnSimulations);


        this.jpGlobalMid.add(this.progressBar);

        this.jpArea.add(this.taResults);

        this.jpControls.add(this.jlPreset);
        this.jpControls.add(this.preset);
        this.jpControls.add(Box.createVerticalGlue());
        this.jpControls.add(this.jbStart);
        this.jpControls.add(Box.createRigidArea(new Dimension(180, 10)));
        this.jpControls.add(this.jbStop);
        this.jpControls.add(Box.createRigidArea(new Dimension(180, 10)));
        this.jpControls.add(this.jbReset);
        this.jpControls.add(Box.createVerticalGlue());
        this.jpControls.add(this.jbQuit);


        this.jpGlobalTop.add(this.jpInputs);
        this.jpGlobalBot.add(this.jpArea);
        this.jpGlobalBot.add(this.jpControls);
        this.jpGlobal.add(this.jpGlobalTop);
        this.jpGlobal.add(this.jpGlobalMid);
        this.jpGlobal.add(this.jpGlobalBot);


    }
}
